<template>
	<block class="warp">
		<view class="box_content" >
			<view class="select  mt10">
				<Select style="width:100%" showTag="cate_name" :listArr="listArr" :itemArr="itemArr"
					@finish="finish"></Select>
			</view>
			<empty v-if="!data.length" style="width: 100%;"></empty>
			<scroll-view  class="shop_item1 " :scroll-x="false" v-if="data.length" scroll-y @scrolltolower="scrolltolower" :refresher-triggered="status"  refresher-enabled @refresherpulling= 'scrolltoupper'>
			<view class="flex" style="flex-wrap: wrap;justify-content: flex-start;">
				<view class="item" v-for="(item,index) in data" :key="index" @click="gotoshopInfo(item.id)"
					>
					<image :src="item.image" style="width: 330rpx;height: 300rpx;border-radius: 10rpx;"
						mode="aspectFill"></image>
					<view class="name">{{item.store_name}}</view>
					<view class="price"><text class="word1">指导价:</text><text
							style="font-size: 24rpx;">￥</text>{{item.price}}</view>
				</view>
			</view>
				
				<!-- <view class="word">加载中~~</view> -->
				<view class="word" v-if="finish">没有更多了~~</view>
			</scroll-view>
		</view>
	</block>
</template>

<script>
	import Select from '../../../components/dropdown-screen/dropdown-screen.vue'
	import empty from '../../../components/empty.vue'
	import {
		parts_products,
		parts_category
	} from '../../../api/api.js'
	export default {
		components: {
			Select,
			empty
		},
		data() {
			return {
				statusBarHeight: "",
				listArr: ['设备类型', '设备品牌'],
				itemArr: [],
				sid: "",
				cid: "",
				data: [],
				page: 1,
				dearr: [],
				status:false,
				finish:false,
			}
		},
		
		created() {
			this.gettype()
			this.statusBarHeight = uni.getStorageSync('statusBarHeight')
			console.log('调用接口1')
			this.dataInit()
		},
		methods: {
			search() {
				uni.navigateTo({
					url: "/pages/package/search/search"
				})
			},
			scrolltoupper() {
				// console.log(222)
				this.dataInit()
			},
			// 分页
			scrolltolower() {
				
				if(this.finish){
					return;
				}
				this.page++
				let data = {
					sid: this.sid,
					cid: this.cid,
					keyword: '',
					limit: 10,
					page: this.page,
				}
				parts_products(data).then(res => {
					if(res.data.length == 0){
						this.finish = true
					}
					this.data = this.data.concat(res.data)
				})
			},
			// 获取零配件分类
			gettype() {
				parts_category().then(res => {
					this.itemArr.push(res.data)
					this.itemArr[1] = res.data[0].children
				})
			},
			// itemClick
			finish(e) {
				console.log('选择', e)
				if (e.$index == 0) {
					this.cid = e.id
					if (e.children.length != 0) {
						this.itemArr[1] = e.children
					} else {
						this.itemArr[1] = this.dearr
					}
				} else {
					this.sid = e.id
				}
				this.dataInit()
			},
			// 初始化
			dataInit() {
				this.finish = false
				this.status = true
				this.page = 1
				console.log('调用接口')
				let data = {
					sid: this.sid,
					cid: this.cid,
					keyword: '',
					limit: 10,
					page: this.page,
				}
				parts_products(data).then(res => {
					this.data = res.data
					console.log(this.status)
					this.status =false
				})
			},
			/* 跳转到详情页 */
			gotoshopInfo: function(shopID) {
				uni.navigateTo({
					url: '/pages/shopInfo/shopInfo?shopID=' + shopID
				})
			},

		}

	}
</script>

<style scoped lang="less">
	.home_top {
		/* padding-left: -25px; */
		background-image: url('http://xiaowen.cool:86/yjky/yjkybg.png');
		background-size: cover;
		width: 750upx;
		height: 370upx;
		padding: 20upx;
		box-sizing: border-box;
		/* background-color: #4cd964; */
		flex-direction: row;
		align-items: center;
	}

	.box_content {
	
		position: absolute;
		top: 0rpx;
		width: 100%;
		height: calc(100% - 160rpx);
		background-color: #FFFFFF;
		bottom: 0;
	}

	.select {
		position: fixed;
		width: 100%;
		background-color: #FFFFFF;
		z-index: 99;
		top: 0rpx;
	}

	.shop_item1 {
		padding: 30rpx;
		padding-top: 40rpx;
		width: 100%;
		display: flex;
		justify-content: flex-start;
		flex-wrap: wrap;
		margin-top: 100rpx;
		align-items: center;
		height: 90%;
		.item {
			margin-left: 10rpx;
			display: block;
			width: 45%;
			height: 400rpx;
			position: relative;
			margin-bottom: 30rpx;

			.name {
				position: absolute;
				top: 310rpx;
				color: #666;
			}

			.price {
				position: absolute;
				top: 355rpx;
				line-height: 40rpx;
				color: #FD3833;
				font-size: 35rpx;

				.word1 {
					color: #999999;
					font-size: 24rpx;
				}
			}
		}
	}
	.word{
		text-align: center;
		color: #999999;
		margin-top: 20rpx;
	}
</style>
